package com.sylar.lelepub;

import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;

public class TabNearActivity extends TabActivity implements OnTabChangeListener, OnClickListener {
	protected Resources mRes;
	private TabHost mTabHost;
	private View btn_title_right;
	private Button btn_title_list;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		setContentView(R.layout.layout_tabnear);

		mRes = getResources();

		mTabHost = (TabHost) findViewById(android.R.id.tabhost);

		mTabHost.setOnTabChangedListener(this);

		mTabHost.addTab(mTabHost.newTabSpec("NEAR_LIST").setIndicator("near_list").setContent(new Intent(this, NearListActivity.class)));
		mTabHost.addTab(mTabHost.newTabSpec("NEAR_MAP").setIndicator("near_map").setContent(new Intent(this, BaiduMapActivity.class)));

		View btn_title_left = findViewById(R.id.btn_title_left);
		btn_title_left.setVisibility(View.GONE);
		btn_title_right = findViewById(R.id.btn_title_right);
		btn_title_right.setVisibility(View.VISIBLE);
		btn_title_right.setOnClickListener(this);
		btn_title_list = (Button) findViewById(R.id.btn_title_list);
		btn_title_list.setVisibility(View.VISIBLE);
		btn_title_list.setOnClickListener(this);
		btn_title_list.setText("列表");

		btn_title_list.performClick();

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_title_list:
//			mTabHost.setCurrentTabByTag("NEAR_LIST");
//			btn_title_list.setVisibility(View.GONE);
//			btn_title_right.setVisibility(View.VISIBLE);
			toListView();
			break;
		case R.id.btn_title_right:
//			mTabHost.setCurrentTabByTag("NEAR_MAP");
//			btn_title_list.setVisibility(View.VISIBLE);
//			btn_title_right.setVisibility(View.GONE);
			toMapView();
			break;
		}
	}

	@Override
	public void onTabChanged(String tabId) {
		Activity activity = getLocalActivityManager().getActivity(tabId);
		if (activity != null) {
			activity.onWindowFocusChanged(true);
		}
		mTabHost.setCurrentTabByTag(tabId);
	}

	void toListView() {
		mTabHost.setCurrentTabByTag("NEAR_LIST");
		btn_title_list.setVisibility(View.GONE);
		btn_title_right.setVisibility(View.VISIBLE);
	}

	void toMapView() {
		mTabHost.setCurrentTabByTag("NEAR_MAP");
		btn_title_list.setVisibility(View.VISIBLE);
		btn_title_right.setVisibility(View.GONE);
	}
}
